package com.example.day01;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.day01.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
       /* binding = ActivityMainBinding.inflate(getLayoutInflater());//实例化
        //获取对应的布局
        View root = binding.getRoot();
        setContentView(root);

        binding.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.tv.setText("李四");
            }
        });
        binding.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "点击了按钮", Toast.LENGTH_SHORT).show();
            }
        });*/
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
        //binding.tv.setText("王五");
        binding.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Toast.makeText(MainActivity.this, "这种写法比较简单", Toast.LENGTH_SHORT).show();
                binding.setUser(new UserInfo("游展坤","666666",18));
            }
        });
        binding.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.setUsername("何乾坤");
            }
        });

        
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding = null;//防止内存泄露
    }
}